//
//  ZH_ClassButtonTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/25.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_ClassButtonTableViewCell.h"
@interface ZH_ClassButtonTableViewCell()
@property (nonatomic,weak)UILabel *contentLabel;
@property (nonatomic,weak)UIImageView *classImage;
@property (nonatomic,weak)UIButton *leftButton;
@property (nonatomic,weak)UIButton *rightButton;
@property (nonatomic,weak)UIButton *bottomButton;
@end
@implementation ZH_ClassButtonTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_ClassButtonTableViewCell";
    ZH_ClassButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_ClassButtonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
}
- (void)loadSubviewConstraints{
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(15));
        make.left.equalTo(self.contentView).offset(FITSCALE(36));
        make.right.equalTo(self.contentView).offset(FITSCALE(-36));
    }];
    [self.classImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).offset(FITSCALE(15));
        make.left.equalTo(self.contentView).offset(FITSCALE(36));
        make.right.equalTo(self.contentView).offset(FITSCALE(-36));
        make.height.mas_equalTo(FITSCALE(141));
    }];
    [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.classImage.mas_bottom).offset(FITSCALE(14));
        make.left.equalTo(self.contentView).offset(FITSCALE(36));
        make.right.equalTo(self.contentView.mas_centerX).offset(FITSCALE(-5));
        make.height.mas_equalTo(FITSCALE(37));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.classImage.mas_bottom).offset(FITSCALE(14));
        make.right.equalTo(self.contentView).offset(FITSCALE(-36));
        make.left.equalTo(self.contentView.mas_centerX).offset(FITSCALE(5));
        make.height.mas_equalTo(FITSCALE(37));
    }];
    [self.bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.leftButton.mas_bottom).offset(FITSCALE(15));
        make.left.equalTo(self.contentView).offset(FITSCALE(36));
        make.right.equalTo(self.contentView).offset(FITSCALE(-36));
        make.height.mas_equalTo(FITSCALE(44));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-10));
    }];
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        if (![data[@"introduction"] isKindOfClass:[NSNull class]]) {
             self.contentLabel.text = data[@"introduction"];
        }
        NSString *string = [NSString stringWithFormat:@"%@",data[@"is_buy"]];
        if ([string isEqualToString:@"1"]) {
            self.rightButton.hidden = YES;
            self.leftButton.hidden = YES;
            self.bottomButton.hidden = NO;
            [self.bottomButton mas_updateConstraints:^(MASConstraintMaker *make) {
                 make.top.equalTo(self.classImage.mas_bottom).offset(FITSCALE(15));
            }];
        }
        else{
            
            self.rightButton.hidden = NO;
            self.leftButton.hidden = NO;
            self.bottomButton.hidden = YES;
            [self.bottomButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.leftButton.mas_bottom).offset(FITSCALE(15));
            }];
        }
    }
}
- (void)updateHidden:(BOOL)isbool{
    self.bottomButton.hidden = YES;
}
- (void)button:(UIButton *)btn{
    if (self.onButtonClick) {
        self.onButtonClick(btn.tag);
    }
}
#pragma mark - getter,setter
- (UILabel *)contentLabel{
    if (!_contentLabel) {
        UILabel *label = [UILabel createLabelWithText:@"课程内容简介, 课程内容简介, 课程内容简介, 课程内容简介, 课程内容简介, 课程内容简介..." font:kFontSize_26];
        [label lableAutoLinefeed];
        [self.contentView addSubview:_contentLabel = label];
    }
    return _contentLabel;
}
- (UIImageView *)classImage{
    if (!_classImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@""];
        image.backgroundColor = kFontColorRed;
        [self.contentView addSubview:_classImage = image];
    }
    return _classImage;
}
- (UIButton *)leftButton{
    if (!_leftButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"加入购物车" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_34;
        button.layer.cornerRadius = FITSCALE(18);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 1;
        [self.contentView addSubview:_leftButton = button];
    }
    return _leftButton;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"立即购买" target:self action:@selector(button:)];
        button.backgroundColor = kFontColorWhite;
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_34;
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.cornerRadius = FITSCALE(18);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 2;
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
- (UIButton *)bottomButton{
    if (!_bottomButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"立即学习" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.titleLabel.font = kFontSize_34;
        button.layer.cornerRadius = FITSCALE(21);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 3;
        [self.contentView addSubview:_bottomButton = button];
    }
    return _bottomButton;
}
@end
